<?php
/*
 * @Author: 李志刚
 * @CopyRight: 2020-2030 衡水山木枝技术服务有限公司
 * @Date: 2021-06-10 17:30:50
 * @Description: 店铺表
 * @LastEditors: 李志刚
 * @LastEditTime: 2021-09-14 18:09:02
 * @FilePath: /qingshanERP/app/Models/QingShanERP/Shop.php
 */

namespace App\Models\QingShanERP;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Shop extends Model
{
    use HasFactory;
    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'shops';

    // 不可以批量赋值的字段，为空则表示都可以
    protected $guarded = [];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * 表明模型是否应该被打上时间戳
     *
     * @var bool
     */
    public $timestamps = true;

    /**
     * 应该被转换成原生类型的属性。
     *
     * @var array
     */
    protected $casts = [
        'status' => 'boolean',
    ];
    // 格式化时间
    protected $appends = ['expires_at_date'];
    public function getExpiresAtDateAttribute(){
        return date('Y-m-d H:i:s',$this->expires_at);
    }
    // 门店下商品
    public function goods(){
        return $this->hasMany('\App\Models\QingShanERP\Good', 'shop_id', 'id');
    }
    public function orders()
    {
        return $this->hasMany('\App\Models\QingShanERP\Order', 'shop_id', 'id');
    }
    // 关联租户
    public function tenant()
    {
        return $this->belongsTo('\App\Models\Tenant\Tenant', 'tenant_id', 'id');
    }
}
